package com.highstockings.service.impl;

import com.github.pagehelper.PageHelper;
import com.highstockings.dao.ModelMapper;
import com.highstockings.model.Model;
import com.highstockings.model.ModelVo;
import com.highstockings.service.ModelService;
import com.highstockings.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by diablo13064 on 2018/3/28.
 */
@Service("ModelService")
public class ModelServiceImpl implements ModelService {
    @Autowired
    ModelMapper modelMapper;
    @Override
    public List<Model> findAllModel() {
        return modelMapper.selectAllModel();
    }

    @Override
    public Model findModelByAlias(String alias) {
        return modelMapper.selectByAlias(alias);
    }

    @Override
    public int addModelAlias(Model model) {
        return modelMapper.insertSelective(model);
    }

    @Override
    public List<Model> findSidebarModelInfo() {
        return modelMapper.selectTop5Model();
    }

    @Override
    public Model findModelById(int id) {
        return modelMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ModelVo> findAllModelVo(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return FileUtil.enhancedTagSet(modelMapper.selectAllModelVo());
    }

    @Override
    public int upModelBuzz(int mid) {
        return modelMapper.updateBuzz(mid);
    }

    @Override
    public List<ModelVo> findRecentModelVo() {
        return FileUtil.enhancedTagSet(modelMapper.selectRecentModel());
    }
}
